﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Net;
using System.IO;

namespace CIT.WMS.Common
{
    public class Bll_Common
    {
        /// <summary>
        /// 通过库位SN获取仓库SN
        /// </summary>
        /// <param name="Location_SN"></param>
        /// <returns></returns>
        public static DataTable GetListOfStorage(string Location_SN)
        {
            string strSql = string.Format(@"SELECT A.Storage_SN,A.Storage_Name,B.Area_SN FROM dbo.T_Bllb_StorageLocation_tbsl C LEFT JOIN dbo.T_Bllb_StorageArea_tbsa B ON C.Area_SN=B.Area_SN
LEFT JOIN dbo.T_Bllb_Storage_tbs A ON B.Storage_SN=A.Storage_SN
WHERE C.Location_SN='{0}'",Location_SN);
            return Utils.NMS.QueryDataTable(Utils.uContext,strSql, new CIT.WMS.MESWcf.CmdParameter[0]);
        }
        private static string HttpPost(string Url, string postDataStr)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = Encoding.UTF8.GetByteCount(postDataStr);
            //request.CookieContainer = cookie;
            Stream myRequestStream = request.GetRequestStream();
            StreamWriter myStreamWriter = new StreamWriter(myRequestStream, Encoding.GetEncoding("gb2312"));
            myStreamWriter.Write(postDataStr);
            myStreamWriter.Close();

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            //response.Cookies = cookie.GetCookies(response.ResponseUri);
            Stream myResponseStream = response.GetResponseStream();
            StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
            string retString = myStreamReader.ReadToEnd();
            myStreamReader.Close();
            myResponseStream.Close();

            return retString;
        }

        public static string HttpGet(string Url, string postDataStr)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url + (postDataStr == "" ? "" : "?") + postDataStr);
            request.Method = "GET";
            request.ContentType = "text/html;charset=UTF-8";

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream myResponseStream = response.GetResponseStream();
            StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));
            string retString = myStreamReader.ReadToEnd();
            myStreamReader.Close();
            myResponseStream.Close();

            return retString;
        }
    }
}
